package com.example.htmlfx.controller;

import com.example.htmlfx.HtmlfxApplication;
import com.example.htmlfx.entity.Customer;
import com.example.htmlfx.view.TableFxmlView;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * 登录测试
 *
 * @author gzkemays
 * @date 2021/8/3
 */
@FXMLController
public class LoginController implements Initializable {
  @FXML private TextField tfUsername;
  @FXML private TextField tfPassword;
  @FXML private Button btnReset;
  @FXML private Button btnLogin;
  private Customer customer = new Customer();

  @FXML
  private void login(ActionEvent event) {
    System.out.println("event = " + event);
    if ("gzkemays".equals(customer.getUser().get())
        && "a96548854".equals(customer.getPassword().get())) {
      HtmlfxApplication.showView(TableFxmlView.class);
    }
  }

  @FXML
  private void reset(ActionEvent event) {
    tfUsername.clear();
    tfPassword.clear();
  }

  @Override
  public void initialize(URL location, ResourceBundle resources) {
    tfUsername.textProperty().bindBidirectional(customer.getUser());
    tfPassword.textProperty().bindBidirectional(customer.getPassword());
    tfUsername.setText("gzkemays");
    tfPassword.setText("a96548854");
  }
}
